package com.java.asvitelskyy.company;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Company company = new Company();
        int inputInMenu = 0;
        do {
            inputInMenu = menu();
            switch (inputInMenu) {
                case 1:
                    company.addFixWorker();
                    break;
                case 2:
                    company.addHourWorker();
                    break;
                case 3:
                    printTableCap();
                    company.listWorkers();
                    print("Please enter number of worker to delete");
                    company.deleteWorker(getInputInt());
                    break;
                case 4:
                    printTableCap();
                    company.sortByName();
                    company.listWorkers();
                    break;
                case 5:
                    printTableCap();
                    company.sortBySalary();
                    company.listWorkers();
                    break;
            }
        } while (inputInMenu != 6);
    }

    public static int menu() {
        int result = 0;
        print("Press 1 to Add new worker with FixSalary");
        print("Press 2 to Add new worker with HourSalary");
        print("Press 3 to Delete worker");
        print("Press 4 to get Workers list sorted by name");
        print("Press 5 to get Workers list sorted by salary");
        print("Press 6 to exit from program");
        do {
            result = getInputInt();
            if (!validateInt(result, 1, 2, 3, 4, 5, 6)) {
                print("Not valid input. Try again:");
            }
        } while (!validateInt(result, 1, 2, 3, 4, 5, 6));
        return result;
    }

    public static int getInputInt() {
        Scanner sc = new Scanner(System.in);
        int result = sc.nextInt();
        return result;
    }

    public static String getInputString() {
        Scanner sc = new Scanner(System.in);
        String result = sc.next();
        return result;
    }

    public static boolean validateInt(int input, int... args) {
        boolean validate = false;
        for (int index = 0; index < args.length; index++) {
            if (input == args[index]) {
                validate = true;
            }
        }
        return validate;
    }

    public static void print(String text) {
        System.out.println(text);
    }

    public static void printTableCap() {
        print(" --------------------------------------------");
        print("|        № |       ID |     Name |   Salary |");
        print(" --------------------------------------------");
    }

}